package com.whut.customer.controller;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/deviation")
@Slf4j
public class DeviationController {

    @ApiOperation("计算偏移量")
    @PostMapping("/deviation")
    public List<String> getDistance(float dia_left, float dia_right){
        List<String> result=new ArrayList();
        float deviation;
        float width = 45.0f - dia_left - dia_right;
        if(dia_left <= dia_right){
            deviation=width/2.0f - (22.5f-dia_right);
            DecimalFormat decimalFormat=new DecimalFormat(".00");
            String p=decimalFormat.format(deviation);
            result.add("往东偏移");
            result.add(p+"米");
            System.out.println(result);
            return result;
        }
        else{
            deviation=width/2.0f - (22.5f-dia_left);
            DecimalFormat decimalFormat=new DecimalFormat(".00");
            String p=decimalFormat.format(deviation);
            result.add("往西偏移");
            result.add(p+"米");
            System.out.println(result);
            return result;
        }
    }
}
